package com.swanclouds.redfish.account.domain.Oem.BMC.role;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.swanclouds.model.account.builder.BMC.BMCCreateUserGroup;
import com.swanclouds.model.account.builder.BMC.BMCCreateRoleBuilder;
import com.swanclouds.redfish.common.utils.StringHepler;

import java.util.List;

/**
 * @author 张立强
 * @version jdk1.8.0
 */
public class BMCCreateUserGroupConcrete implements BMCCreateUserGroup {

    @JsonProperty("RoleId")
    private String privileges;

    @JsonProperty("Name")
    private String name;

    @JsonProperty("OemPrivileges")
    private List<String> oemPrivileges;

    /**
     * 包括： Administrator  Operator  User  None  Oem
     *
     * @return Privileges
     */
    @Override
    public String getPrivileges() {
        return this.privileges;
    }

    /**
     * 用户组名称(角色名称)
     *
     * @return name
     */
    @Override
    public String getName() {
        return this.name;
    }

    /**
     * 服务器自定义的权限类型
     * <p>
     * BMC: SNMP,Vmedia,KVM
     * <p>
     *
     * @return java.util.List&lt;String&gt; OemPrivileges
     */
    @Override
    public List<String> getOemPrivileges() {
        return this.oemPrivileges;
    }

    @Override
    public BMCCreateRoleBuilder toBuilder() {
        return new BMCCreateRoleConcreteBuilder();
    }

    public static BMCCreateRoleBuilder builder() {
        return new BMCCreateUserGroupConcrete().toBuilder();
    }

    public static class BMCCreateRoleConcreteBuilder implements BMCCreateRoleBuilder {

        public BMCCreateUserGroupConcrete m;

        public BMCCreateRoleConcreteBuilder() {
            this(new BMCCreateUserGroupConcrete());
        }

        public BMCCreateRoleConcreteBuilder(BMCCreateUserGroupConcrete m) {
            this.m = m;
        }
        /**
         * 包括： Administrator  Operator  User  None  Oem
         *
         * @param privileges 角色
         * @return Privileges
         */
        @Override
        public BMCCreateRoleBuilder Privileges(String privileges) {
            m.privileges = privileges;
            return this;
        }

        /**
         * 用户组名称(角色名称)
         *
         * @param name 用户组名称
         * @return name
         */
        @Override
        public BMCCreateRoleBuilder Name(String name) {
            m.name = name;
            return this;
        }

        /**
         * 服务器自定义的权限类型
         * <p>
         * BMC: SNMP,Vmedia,KVM
         * <p>
         *
         * @param oemPrivileges 权限类型
         * @return BMCCreateRoleBuilder
         */
        @Override
        public BMCCreateRoleBuilder OemPrivileges(List<String> oemPrivileges) {
            m.oemPrivileges = oemPrivileges;
            return this;
        }

        @Override
        public BMCCreateRoleBuilder AddOemPrivilege(String oemPrivilege) {
            m.oemPrivileges = Lists.newArrayList();
            if (StringHepler.isNotBlank(oemPrivilege)) {
                m.oemPrivileges.add(oemPrivilege);
            }
            return this;
        }

        /**
         * Creates and return the Model Entity M
         *
         * @return M instance
         */
        @Override
        public BMCCreateUserGroup build() {
            return m;
        }

        /**
         * Creates a Builder using the param M as the default values
         *
         * @param in The Model M
         * @return Builder
         */
        @Override
        public BMCCreateRoleBuilder from(BMCCreateUserGroup in) {
            m = (BMCCreateUserGroupConcrete) in;
            return this;
        }

        @Override
        public String toString() {
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                return objectMapper.writeValueAsString(this);
            } catch (JsonProcessingException e) {
            }
            return "BMCCreateRoleConcreteBuilder {" +
                    "m=" + m +
                    '}';
        }
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "BMCCreateUserGroupConcrete {" +
                "Privileges=" + privileges +
                ", Name='" + name + '\'' +
                ", OemPrivileges=" + oemPrivileges +
                '}';
    }
}
